/* try to solve two-sum, three sum, and n-sum problem*/

// just use two For statements to iterate the array, and the algorithm complexity is O(n^2) 
let twoSum_1 = (array) => {
    if (array === 'undefined' || !Array.isArray(array)) {
        throw Error('Illegal Arguments');
    }
    array = array.filter(elem => !isNaN(parseInt(elem, 10))).map(elem => parseInt(elem, 10));
    if (array.length < 2) {
        throw Error('Need More Numbers');
    }
    let count = 0;
    for (let i = 0; i < array.length; i++) {
        for (let j = i + 1; j < array.length; j++) {
            if (array[i] + array[j] === 0) {
                count++;
            }
        }
    }
    return count;
};
